<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>pathdeform.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-painting-deform-example.html">Vector Deformation</a></td><td >pathdeform.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">pathdeform.cpp 示例文件</h1>
<span class="subtitle">painting/deform/pathdeform.cpp</span>
<!-- $$$painting/deform/pathdeform.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the demonstration applications of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &quot;pathdeform.h&quot;</span>

  <span class="preprocessor">#include &lt;QGuiApplication&gt;</span>
  <span class="preprocessor">#include &lt;QScreen&gt;</span>
  <span class="preprocessor">#include &lt;QtDebug&gt;</span>
  <span class="preprocessor">#include &lt;QMouseEvent&gt;</span>
  <span class="preprocessor">#include &lt;QTimerEvent&gt;</span>
  <span class="preprocessor">#include &lt;QLayout&gt;</span>
  <span class="preprocessor">#include &lt;QLineEdit&gt;</span>
  <span class="preprocessor">#include &lt;QPainter&gt;</span>
  <span class="preprocessor">#include &lt;QSlider&gt;</span>
  <span class="preprocessor">#include &lt;QLabel&gt;</span>
  <span class="preprocessor">#include &lt;QDesktopWidget&gt;</span>
  <span class="preprocessor">#include &lt;qmath.h&gt;</span>

  PathDeformControls<span class="operator">::</span>PathDeformControls(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent<span class="operator">,</span>
                                         PathDeformRenderer<span class="operator">*</span> renderer<span class="operator">,</span> bool smallScreen)
        : <span class="type"><a href="qwidget.html">QWidget</a></span>(parent)
  {
      m_renderer <span class="operator">=</span> renderer;

      <span class="keyword">if</span> (smallScreen)
          layoutForSmallScreen();
      <span class="keyword">else</span>
          layoutForDesktop();
  }

  <span class="type">void</span> PathDeformControls<span class="operator">::</span>layoutForDesktop()
  {
      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span><span class="operator">*</span> mainGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(<span class="keyword">this</span>);
      mainGroup<span class="operator">-</span><span class="operator">&gt;</span>setTitle(tr(<span class="string">&quot;Controls&quot;</span>));

      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>radiusGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(mainGroup);
      radiusGroup<span class="operator">-</span><span class="operator">&gt;</span>setTitle(tr(<span class="string">&quot;Lens Radius&quot;</span>));
      <span class="type"><a href="qslider.html">QSlider</a></span> <span class="operator">*</span>radiusSlider <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qslider.html">QSlider</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Horizontal<span class="operator">,</span> radiusGroup);
      radiusSlider<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">15</span><span class="operator">,</span> <span class="number">150</span>);
      radiusSlider<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Preferred<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Fixed);

      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>deformGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(mainGroup);
      deformGroup<span class="operator">-</span><span class="operator">&gt;</span>setTitle(tr(<span class="string">&quot;Deformation&quot;</span>));
      <span class="type"><a href="qslider.html">QSlider</a></span> <span class="operator">*</span>deformSlider <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qslider.html">QSlider</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Horizontal<span class="operator">,</span> deformGroup);
      deformSlider<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="operator">-</span><span class="number">100</span><span class="operator">,</span> <span class="number">100</span>);
      deformSlider<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Preferred<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Fixed);

      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>fontSizeGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(mainGroup);
      fontSizeGroup<span class="operator">-</span><span class="operator">&gt;</span>setTitle(tr(<span class="string">&quot;Font Size&quot;</span>));
      <span class="type"><a href="qslider.html">QSlider</a></span> <span class="operator">*</span>fontSizeSlider <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qslider.html">QSlider</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Horizontal<span class="operator">,</span> fontSizeGroup);
      fontSizeSlider<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">16</span><span class="operator">,</span> <span class="number">200</span>);
      fontSizeSlider<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Preferred<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Fixed);

      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>textGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(mainGroup);
      textGroup<span class="operator">-</span><span class="operator">&gt;</span>setTitle(tr(<span class="string">&quot;Text&quot;</span>));
      <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>textInput <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>(textGroup);

      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>animateButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(mainGroup);
      animateButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Animated&quot;</span>));
      animateButton<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);

      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>showSourceButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(mainGroup);
      showSourceButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Show Source&quot;</span>));

  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>enableOpenGLButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(mainGroup);
      enableOpenGLButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Use OpenGL&quot;</span>));
      enableOpenGLButton<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);
      enableOpenGLButton<span class="operator">-</span><span class="operator">&gt;</span>setChecked(m_renderer<span class="operator">-</span><span class="operator">&gt;</span>usesOpenGL());
  <span class="preprocessor">#endif</span>

      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>whatsThisButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(mainGroup);
      whatsThisButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;What's This?&quot;</span>));
      whatsThisButton<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);

      mainGroup<span class="operator">-</span><span class="operator">&gt;</span>setFixedWidth(<span class="number">180</span>);

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>mainGroupLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(mainGroup);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(radiusGroup);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(deformGroup);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fontSizeGroup);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(textGroup);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(animateButton);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addStretch(<span class="number">1</span>);
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(enableOpenGLButton);
  <span class="preprocessor">#endif</span>
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(showSourceButton);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(whatsThisButton);

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>radiusGroupLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(radiusGroup);
      radiusGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(radiusSlider);

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>deformGroupLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(deformGroup);
      deformGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(deformSlider);

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>fontSizeGroupLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(fontSizeGroup);
      fontSizeGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fontSizeSlider);

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>textGroupLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(textGroup);
      textGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(textInput);

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span> mainLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(<span class="keyword">this</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(mainGroup);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>setMargin(<span class="number">0</span>);

      connect(radiusSlider<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(setRadius(<span class="type">int</span>)));
      connect(deformSlider<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(setIntensity(<span class="type">int</span>)));
      connect(fontSizeSlider<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(setFontSize(<span class="type">int</span>)));
      connect(animateButton<span class="operator">,</span> SIGNAL(clicked(bool))<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(setAnimated(bool)));
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      connect(enableOpenGLButton<span class="operator">,</span> SIGNAL(clicked(bool))<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(enableOpenGL(bool)));
  <span class="preprocessor">#endif</span>

      connect(textInput<span class="operator">,</span> SIGNAL(textChanged(<span class="type"><a href="../qtcore/qstring.html">QString</a></span>))<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(setText(<span class="type"><a href="../qtcore/qstring.html">QString</a></span>)));
      connect(m_renderer<span class="operator">,</span> SIGNAL(descriptionEnabledChanged(bool))<span class="operator">,</span>
              whatsThisButton<span class="operator">,</span> SLOT(setChecked(bool)));
      connect(whatsThisButton<span class="operator">,</span> SIGNAL(clicked(bool))<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(setDescriptionEnabled(bool)));
      connect(showSourceButton<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(showSource()));

      animateButton<span class="operator">-</span><span class="operator">&gt;</span>animateClick();
      deformSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">80</span>);
      fontSizeSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">120</span>);
      radiusSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">100</span>);
      textInput<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Qt&quot;</span>));
  }

  <span class="type">void</span> PathDeformControls<span class="operator">::</span>layoutForSmallScreen()
  {
      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span><span class="operator">*</span> mainGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(<span class="keyword">this</span>);
      mainGroup<span class="operator">-</span><span class="operator">&gt;</span>setTitle(tr(<span class="string">&quot;Controls&quot;</span>));

      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>radiusLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(mainGroup);
      radiusLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Lens Radius:&quot;</span>));
      <span class="type"><a href="qslider.html">QSlider</a></span> <span class="operator">*</span>radiusSlider <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qslider.html">QSlider</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Horizontal<span class="operator">,</span> mainGroup);
      radiusSlider<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">15</span><span class="operator">,</span> <span class="number">150</span>);
      radiusSlider<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Expanding<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Fixed);

      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>deformLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(mainGroup);
      deformLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Deformation:&quot;</span>));
      <span class="type"><a href="qslider.html">QSlider</a></span> <span class="operator">*</span>deformSlider <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qslider.html">QSlider</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Horizontal<span class="operator">,</span> mainGroup);
      deformSlider<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="operator">-</span><span class="number">100</span><span class="operator">,</span> <span class="number">100</span>);
      deformSlider<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Expanding<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Fixed);

      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>fontSizeLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(mainGroup);
      fontSizeLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Font Size:&quot;</span>));
      <span class="type"><a href="qslider.html">QSlider</a></span> <span class="operator">*</span>fontSizeSlider <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qslider.html">QSlider</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Horizontal<span class="operator">,</span> mainGroup);
      fontSizeSlider<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">16</span><span class="operator">,</span> <span class="number">200</span>);
      fontSizeSlider<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Expanding<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Fixed);

      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>animateButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">&quot;Animated&quot;</span>)<span class="operator">,</span> mainGroup);
      animateButton<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);

  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>enableOpenGLButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(mainGroup);
      enableOpenGLButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Use OpenGL&quot;</span>));
      enableOpenGLButton<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(mainGroup);
      enableOpenGLButton<span class="operator">-</span><span class="operator">&gt;</span>setChecked(m_renderer<span class="operator">-</span><span class="operator">&gt;</span>usesOpenGL());
  <span class="preprocessor">#endif</span>

      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>quitButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">&quot;Quit&quot;</span>)<span class="operator">,</span> mainGroup);
      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>okButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">&quot;OK&quot;</span>)<span class="operator">,</span> mainGroup);

      <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>mainGroupLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>(mainGroup);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>setMargin(<span class="number">0</span>);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(radiusLabel<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AlignRight);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(radiusSlider<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(deformLabel<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AlignRight);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(deformSlider<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fontSizeLabel<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AlignRight);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fontSizeSlider<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">1</span>);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(animateButton<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span><span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span><span class="number">2</span>);
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(enableOpenGLButton<span class="operator">,</span> <span class="number">4</span><span class="operator">,</span><span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span><span class="number">2</span>);
  <span class="preprocessor">#endif</span>

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>mainLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(<span class="keyword">this</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(mainGroup);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addStretch(<span class="number">1</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(okButton);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(quitButton);

      connect(quitButton<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SIGNAL(quitPressed()));
      connect(okButton<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SIGNAL(okPressed()));
      connect(radiusSlider<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(setRadius(<span class="type">int</span>)));
      connect(deformSlider<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(setIntensity(<span class="type">int</span>)));
      connect(fontSizeSlider<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(setFontSize(<span class="type">int</span>)));
      connect(animateButton<span class="operator">,</span> SIGNAL(clicked(bool))<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(setAnimated(bool)));
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      connect(enableOpenGLButton<span class="operator">,</span> SIGNAL(clicked(bool))<span class="operator">,</span> m_renderer<span class="operator">,</span> SLOT(enableOpenGL(bool)));
  <span class="preprocessor">#endif</span>

      animateButton<span class="operator">-</span><span class="operator">&gt;</span>animateClick();
      deformSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">80</span>);
      fontSizeSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">120</span>);

      <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> screen_size <span class="operator">=</span> <span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>primaryScreen()<span class="operator">-</span><span class="operator">&gt;</span>geometry();
      radiusSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(<a href="../qtcore/qtglobal.html#qMin">qMin</a>(screen_size<span class="operator">.</span>width()<span class="operator">,</span> screen_size<span class="operator">.</span>height())<span class="operator">/</span><span class="number">5</span>);

      m_renderer<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Qt&quot;</span>));
  }

  PathDeformWidget<span class="operator">::</span>PathDeformWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent<span class="operator">,</span> bool smallScreen)
      : <span class="type"><a href="qwidget.html">QWidget</a></span>(parent)
  {
      setWindowTitle(tr(<span class="string">&quot;Vector Deformation&quot;</span>));

      m_renderer <span class="operator">=</span> <span class="keyword">new</span> PathDeformRenderer(<span class="keyword">this</span><span class="operator">,</span> smallScreen);
      m_renderer<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Expanding<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Expanding);

      <span class="comment">// Layouts</span>
      <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>mainLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>(<span class="keyword">this</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(m_renderer);

      m_controls <span class="operator">=</span> <span class="keyword">new</span> PathDeformControls(<span class="number">0</span><span class="operator">,</span> m_renderer<span class="operator">,</span> smallScreen);
      m_controls<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Fixed<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Minimum);

      <span class="keyword">if</span> (<span class="operator">!</span>smallScreen)
          mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(m_controls);

      m_renderer<span class="operator">-</span><span class="operator">&gt;</span>loadSourceFile(<span class="string">&quot;:res/deform/pathdeform.cpp&quot;</span>);
      m_renderer<span class="operator">-</span><span class="operator">&gt;</span>loadDescription(<span class="string">&quot;:res/deform/pathdeform.html&quot;</span>);
      m_renderer<span class="operator">-</span><span class="operator">&gt;</span>setDescriptionEnabled(<span class="keyword">false</span>);

      connect(m_renderer<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(showControls()));
      connect(m_controls<span class="operator">,</span> SIGNAL(okPressed())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(hideControls()));
      connect(m_controls<span class="operator">,</span> SIGNAL(quitPressed())<span class="operator">,</span> <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>instance()<span class="operator">,</span> SLOT(quit()));
  }

  <span class="type">void</span> PathDeformWidget<span class="operator">::</span>showControls()
  {
      m_controls<span class="operator">-</span><span class="operator">&gt;</span>showFullScreen();
  }

  <span class="type">void</span> PathDeformWidget<span class="operator">::</span>hideControls()
  {
      m_controls<span class="operator">-</span><span class="operator">&gt;</span>hide();
  }

  <span class="type">void</span> PathDeformWidget<span class="operator">::</span>setStyle( <span class="type"><a href="qstyle.html">QStyle</a></span> <span class="operator">*</span> style )
  {
      <span class="type"><a href="qwidget.html">QWidget</a></span><span class="operator">::</span>setStyle(style);
      <span class="keyword">if</span> (m_controls <span class="operator">=</span><span class="operator">=</span> <span class="number">0</span>)
          <span class="keyword">return</span>;

      m_controls<span class="operator">-</span><span class="operator">&gt;</span>setStyle(style);

      <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span><span class="operator">&gt;</span> widgets <span class="operator">=</span> m_controls<span class="operator">-</span><span class="operator">&gt;</span>findChildren<span class="operator">&lt;</span><span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span><span class="operator">&gt;</span>();
      foreach (<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>w<span class="operator">,</span> widgets)
          w<span class="operator">-</span><span class="operator">&gt;</span>setStyle(style);
  }

  <span class="keyword">static</span> <span class="keyword">inline</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> circle_bounds(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> <span class="operator">&amp;</span>center<span class="operator">,</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> radius<span class="operator">,</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> compensation)
  {
      <span class="keyword">return</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span>(<a href="../qtcore/qtglobal.html#qRound">qRound</a>(center<span class="operator">.</span>x() <span class="operator">-</span> radius <span class="operator">-</span> compensation)<span class="operator">,</span>
                   <a href="../qtcore/qtglobal.html#qRound">qRound</a>(center<span class="operator">.</span>y() <span class="operator">-</span> radius <span class="operator">-</span> compensation)<span class="operator">,</span>
                   <a href="../qtcore/qtglobal.html#qRound">qRound</a>((radius <span class="operator">+</span> compensation) <span class="operator">*</span> <span class="number">2</span>)<span class="operator">,</span>
                   <a href="../qtcore/qtglobal.html#qRound">qRound</a>((radius <span class="operator">+</span> compensation) <span class="operator">*</span> <span class="number">2</span>));

  }

  <span class="keyword">const</span> <span class="type">int</span> LENS_EXTENT <span class="operator">=</span> <span class="number">10</span>;

  PathDeformRenderer<span class="operator">::</span>PathDeformRenderer(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget<span class="operator">,</span> bool smallScreen)
      : ArthurFrame(widget)
  {
      m_radius <span class="operator">=</span> <span class="number">100</span>;
      m_pos <span class="operator">=</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(m_radius<span class="operator">,</span> m_radius);
      m_direction <span class="operator">=</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(<span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
      m_fontSize <span class="operator">=</span> <span class="number">24</span>;
      m_animated <span class="operator">=</span> <span class="keyword">true</span>;
      m_repaintTimer<span class="operator">.</span>start(<span class="number">25</span><span class="operator">,</span> <span class="keyword">this</span>);
      m_repaintTracker<span class="operator">.</span>start();
      m_intensity <span class="operator">=</span> <span class="number">100</span>;
      m_smallScreen <span class="operator">=</span> smallScreen;

  <span class="comment">//     m_fpsTimer.start(1000, this);</span>
  <span class="comment">//     m_fpsCounter = 0;</span>

      generateLensPixmap();
  }

  <span class="type">void</span> PathDeformRenderer<span class="operator">::</span>setText(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>text)
  {
      m_text <span class="operator">=</span> text;

      <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> f(<span class="string">&quot;times new roman,utopia&quot;</span>);
      f<span class="operator">.</span>setStyleStrategy(<span class="type"><a href="../qtgui/qfont.html">QFont</a></span><span class="operator">::</span>ForceOutline);
      f<span class="operator">.</span>setPointSize(m_fontSize);
      f<span class="operator">.</span>setStyleHint(<span class="type"><a href="../qtgui/qfont.html">QFont</a></span><span class="operator">::</span>Times);

      <span class="type"><a href="../qtgui/qfontmetrics.html">QFontMetrics</a></span> fm(f);

      m_paths<span class="operator">.</span>clear();
      m_pathBounds <span class="operator">=</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span>();

      <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> advance(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);

      bool do_quick <span class="operator">=</span> <span class="keyword">true</span>;
      <span class="keyword">for</span> (<span class="type">int</span> i<span class="operator">=</span><span class="number">0</span>; i<span class="operator">&lt;</span>text<span class="operator">.</span>size(); <span class="operator">+</span><span class="operator">+</span>i) {
          <span class="keyword">if</span> (text<span class="operator">.</span>at(i)<span class="operator">.</span>unicode() <span class="operator">&gt;</span><span class="operator">=</span> <span class="number">0x4ff</span> <span class="operator">&amp;</span><span class="operator">&amp;</span> text<span class="operator">.</span>at(i)<span class="operator">.</span>unicode() <span class="operator">&lt;</span><span class="operator">=</span> <span class="number">0x1e00</span>) {
              do_quick <span class="operator">=</span> <span class="keyword">false</span>;
              <span class="keyword">break</span>;
          }
      }

      <span class="keyword">if</span> (do_quick) {
          <span class="keyword">for</span> (<span class="type">int</span> i<span class="operator">=</span><span class="number">0</span>; i<span class="operator">&lt;</span>text<span class="operator">.</span>size(); <span class="operator">+</span><span class="operator">+</span>i) {
              <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> path;
              path<span class="operator">.</span>addText(advance<span class="operator">,</span> f<span class="operator">,</span> text<span class="operator">.</span>mid(i<span class="operator">,</span> <span class="number">1</span>));
              m_pathBounds <span class="operator">|</span><span class="operator">=</span> path<span class="operator">.</span>boundingRect();
              m_paths <span class="operator">&lt;</span><span class="operator">&lt;</span> path;
              advance <span class="operator">+</span><span class="operator">=</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(fm<span class="operator">.</span>horizontalAdvance(text<span class="operator">.</span>mid(i<span class="operator">,</span> <span class="number">1</span>))<span class="operator">,</span> <span class="number">0</span>);
          }
      } <span class="keyword">else</span> {
          <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> path;
          path<span class="operator">.</span>addText(advance<span class="operator">,</span> f<span class="operator">,</span> text);
          m_pathBounds <span class="operator">|</span><span class="operator">=</span> path<span class="operator">.</span>boundingRect();
          m_paths <span class="operator">&lt;</span><span class="operator">&lt;</span> path;
      }

      <span class="keyword">for</span> (<span class="type">int</span> i<span class="operator">=</span><span class="number">0</span>; i<span class="operator">&lt;</span>m_paths<span class="operator">.</span>size(); <span class="operator">+</span><span class="operator">+</span>i)
          m_paths<span class="operator">[</span>i<span class="operator">]</span> <span class="operator">=</span> m_paths<span class="operator">[</span>i<span class="operator">]</span> <span class="operator">*</span> <span class="type"><a href="../qtgui/qmatrix.html">QMatrix</a></span>(<span class="number">1</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="operator">-</span>m_pathBounds<span class="operator">.</span>x()<span class="operator">,</span> <span class="operator">-</span>m_pathBounds<span class="operator">.</span>y());

      update();
  }

  <span class="type">void</span> PathDeformRenderer<span class="operator">::</span>generateLensPixmap()
  {
      <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> rad <span class="operator">=</span> m_radius <span class="operator">+</span> LENS_EXTENT;

      <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> bounds <span class="operator">=</span> circle_bounds(<span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>()<span class="operator">,</span> rad<span class="operator">,</span> <span class="number">0</span>);

      <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> painter;

      <span class="keyword">if</span> (preferImage()) {
          m_lens_image <span class="operator">=</span> <span class="type"><a href="../qtgui/qimage.html">QImage</a></span>(bounds<span class="operator">.</span>size()<span class="operator">,</span> <span class="type"><a href="../qtgui/qimage.html">QImage</a></span><span class="operator">::</span>Format_ARGB32_Premultiplied);
          m_lens_image<span class="operator">.</span>fill(<span class="number">0</span>);
          painter<span class="operator">.</span>begin(<span class="operator">&amp;</span>m_lens_image);
      } <span class="keyword">else</span> {
          m_lens_pixmap <span class="operator">=</span> <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(bounds<span class="operator">.</span>size());
          m_lens_pixmap<span class="operator">.</span>fill(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>transparent);
          painter<span class="operator">.</span>begin(<span class="operator">&amp;</span>m_lens_pixmap);
      }

      <span class="type"><a href="../qtgui/qradialgradient.html">QRadialGradient</a></span> gr(rad<span class="operator">,</span> rad<span class="operator">,</span> rad<span class="operator">,</span> <span class="number">3</span> <span class="operator">*</span> rad <span class="operator">/</span> <span class="number">5</span><span class="operator">,</span> <span class="number">3</span> <span class="operator">*</span> rad <span class="operator">/</span> <span class="number">5</span>);
      gr<span class="operator">.</span>setColorAt(<span class="number">0.0</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span>(<span class="number">255</span><span class="operator">,</span> <span class="number">255</span><span class="operator">,</span> <span class="number">255</span><span class="operator">,</span> <span class="number">191</span>));
      gr<span class="operator">.</span>setColorAt(<span class="number">0.2</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span>(<span class="number">255</span><span class="operator">,</span> <span class="number">255</span><span class="operator">,</span> <span class="number">127</span><span class="operator">,</span> <span class="number">191</span>));
      gr<span class="operator">.</span>setColorAt(<span class="number">0.9</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span>(<span class="number">150</span><span class="operator">,</span> <span class="number">150</span><span class="operator">,</span> <span class="number">200</span><span class="operator">,</span> <span class="number">63</span>));
      gr<span class="operator">.</span>setColorAt(<span class="number">0.95</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">127</span>));
      gr<span class="operator">.</span>setColorAt(<span class="number">1</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>));
      painter<span class="operator">.</span>setRenderHint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>Antialiasing);
      painter<span class="operator">.</span>setBrush(gr);
      painter<span class="operator">.</span>setPen(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>NoPen);
      painter<span class="operator">.</span>drawEllipse(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> bounds<span class="operator">.</span>width()<span class="operator">,</span> bounds<span class="operator">.</span>height());
  }

  <span class="type">void</span> PathDeformRenderer<span class="operator">::</span>setAnimated(bool animated)
  {
      m_animated <span class="operator">=</span> animated;

      <span class="keyword">if</span> (m_animated) {
  <span class="comment">//         m_fpsTimer.start(1000, this);</span>
  <span class="comment">//         m_fpsCounter = 0;</span>
          m_repaintTimer<span class="operator">.</span>start(<span class="number">25</span><span class="operator">,</span> <span class="keyword">this</span>);
          m_repaintTracker<span class="operator">.</span>start();
      } <span class="keyword">else</span> {
  <span class="comment">//         m_fpsTimer.stop();</span>
          m_repaintTimer<span class="operator">.</span>stop();
      }
  }

  <span class="type">void</span> PathDeformRenderer<span class="operator">::</span>timerEvent(<span class="type"><a href="../qtcore/qtimerevent.html">QTimerEvent</a></span> <span class="operator">*</span>e)
  {

      <span class="keyword">if</span> (e<span class="operator">-</span><span class="operator">&gt;</span>timerId() <span class="operator">=</span><span class="operator">=</span> m_repaintTimer<span class="operator">.</span>timerId()) {

          <span class="keyword">if</span> (<span class="type"><a href="../qtcore/qlinef.html">QLineF</a></span>(<span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(<span class="number">0</span><span class="operator">,</span><span class="number">0</span>)<span class="operator">,</span> m_direction)<span class="operator">.</span>length() <span class="operator">&gt;</span> <span class="number">1</span>)
              m_direction <span class="operator">*</span><span class="operator">=</span> <span class="number">0.995</span>;
          <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> time <span class="operator">=</span> m_repaintTracker<span class="operator">.</span>restart();

          <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> rectBefore <span class="operator">=</span> circle_bounds(m_pos<span class="operator">,</span> m_radius<span class="operator">,</span> m_fontSize);

          <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> dx <span class="operator">=</span> m_direction<span class="operator">.</span>x();
          <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> dy <span class="operator">=</span> m_direction<span class="operator">.</span>y();
          <span class="keyword">if</span> (time <span class="operator">&gt;</span> <span class="number">0</span>) {
              dx <span class="operator">=</span> dx <span class="operator">*</span> time <span class="operator">*</span> <span class="operator">.</span><span class="number">1</span>;
              dy <span class="operator">=</span> dy <span class="operator">*</span> time <span class="operator">*</span> <span class="operator">.</span><span class="number">1</span>;
          }

          m_pos <span class="operator">+</span><span class="operator">=</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(dx<span class="operator">,</span> dy);

          <span class="keyword">if</span> (m_pos<span class="operator">.</span>x() <span class="operator">-</span> m_radius <span class="operator">&lt;</span> <span class="number">0</span>) {
              m_direction<span class="operator">.</span>setX(<span class="operator">-</span>m_direction<span class="operator">.</span>x());
              m_pos<span class="operator">.</span>setX(m_radius);
          } <span class="keyword">else</span> <span class="keyword">if</span> (m_pos<span class="operator">.</span>x() <span class="operator">+</span> m_radius <span class="operator">&gt;</span> width()) {
              m_direction<span class="operator">.</span>setX(<span class="operator">-</span>m_direction<span class="operator">.</span>x());
              m_pos<span class="operator">.</span>setX(width() <span class="operator">-</span> m_radius);
          }

          <span class="keyword">if</span> (m_pos<span class="operator">.</span>y() <span class="operator">-</span> m_radius <span class="operator">&lt;</span> <span class="number">0</span>) {
              m_direction<span class="operator">.</span>setY(<span class="operator">-</span>m_direction<span class="operator">.</span>y());
              m_pos<span class="operator">.</span>setY(m_radius);
          } <span class="keyword">else</span> <span class="keyword">if</span> (m_pos<span class="operator">.</span>y() <span class="operator">+</span> m_radius <span class="operator">&gt;</span> height()) {
              m_direction<span class="operator">.</span>setY(<span class="operator">-</span>m_direction<span class="operator">.</span>y());
              m_pos<span class="operator">.</span>setY(height() <span class="operator">-</span> m_radius);
          }

  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
          <span class="keyword">if</span> (usesOpenGL()) {
              update();
          } <span class="keyword">else</span>
  <span class="preprocessor">#endif</span>
          {
              <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> rectAfter <span class="operator">=</span> circle_bounds(m_pos<span class="operator">,</span> m_radius<span class="operator">,</span> m_fontSize);
              update(rectAfter <span class="operator">|</span> rectBefore);
          }
      }
  <span class="comment">//     else if (e-&gt;timerId() == m_fpsTimer.timerId()) {</span>
  <span class="comment">//         printf(&quot;fps: %d\n&quot;, m_fpsCounter);</span>
  <span class="comment">//         emit frameRate(m_fpsCounter);</span>
  <span class="comment">//         m_fpsCounter = 0;</span>

  <span class="comment">//     }</span>
  }

  <span class="type">void</span> PathDeformRenderer<span class="operator">::</span>mousePressEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>e)
  {
      <span class="keyword">if</span> (m_show_doc) {
          setDescriptionEnabled(<span class="keyword">false</span>);
          <span class="keyword">return</span>;
      }
      setDescriptionEnabled(<span class="keyword">false</span>);

      m_repaintTimer<span class="operator">.</span>stop();
      m_offset <span class="operator">=</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>();
      <span class="keyword">if</span> (<span class="type"><a href="../qtcore/qlinef.html">QLineF</a></span>(m_pos<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>pos())<span class="operator">.</span>length() <span class="operator">&lt;</span><span class="operator">=</span> m_radius)
          m_offset <span class="operator">=</span> m_pos <span class="operator">-</span> e<span class="operator">-</span><span class="operator">&gt;</span>pos();

      m_mousePress <span class="operator">=</span> e<span class="operator">-</span><span class="operator">&gt;</span>pos();

      <span class="comment">// If we're not running in small screen mode, always assume we're dragging</span>
      m_mouseDrag <span class="operator">=</span> <span class="operator">!</span>m_smallScreen;

      mouseMoveEvent(e);
  }

  <span class="type">void</span> PathDeformRenderer<span class="operator">::</span>mouseReleaseEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>e)
  {
      <span class="keyword">if</span> (e<span class="operator">-</span><span class="operator">&gt;</span>buttons() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>NoButton <span class="operator">&amp;</span><span class="operator">&amp;</span> m_animated) {
          m_repaintTimer<span class="operator">.</span>start(<span class="number">10</span><span class="operator">,</span> <span class="keyword">this</span>);
          m_repaintTracker<span class="operator">.</span>start();
      }

      <span class="keyword">if</span> (<span class="operator">!</span>m_mouseDrag <span class="operator">&amp;</span><span class="operator">&amp;</span> m_smallScreen)
          <span class="keyword">emit</span> clicked();
  }

  <span class="type">void</span> PathDeformRenderer<span class="operator">::</span>mouseMoveEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>e)
  {
      <span class="keyword">if</span> (<span class="operator">!</span>m_mouseDrag <span class="operator">&amp;</span><span class="operator">&amp;</span> (<span class="type"><a href="../qtcore/qlinef.html">QLineF</a></span>(m_mousePress<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>pos())<span class="operator">.</span>length() <span class="operator">&gt;</span> <span class="number">25.0</span>) )
          m_mouseDrag <span class="operator">=</span> <span class="keyword">true</span>;

      <span class="keyword">if</span> (m_mouseDrag) {
          <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> rectBefore <span class="operator">=</span> circle_bounds(m_pos<span class="operator">,</span> m_radius<span class="operator">,</span> m_fontSize);
          <span class="keyword">if</span> (e<span class="operator">-</span><span class="operator">&gt;</span>type() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="../qtcore/qevent.html">QEvent</a></span><span class="operator">::</span>MouseMove) {
              <span class="type"><a href="../qtcore/qlinef.html">QLineF</a></span> line(m_pos<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>pos() <span class="operator">+</span> m_offset);
              line<span class="operator">.</span>setLength(line<span class="operator">.</span>length() <span class="operator">*</span> <span class="operator">.</span><span class="number">1</span>);
              <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> dir(line<span class="operator">.</span>dx()<span class="operator">,</span> line<span class="operator">.</span>dy());
              m_direction <span class="operator">=</span> (m_direction <span class="operator">+</span> dir) <span class="operator">/</span> <span class="number">2</span>;
          }
          m_pos <span class="operator">=</span> e<span class="operator">-</span><span class="operator">&gt;</span>pos() <span class="operator">+</span> m_offset;
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
          <span class="keyword">if</span> (usesOpenGL()) {
              update();
          } <span class="keyword">else</span>
  <span class="preprocessor">#endif</span>
          {
              <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> rectAfter <span class="operator">=</span> circle_bounds(m_pos<span class="operator">,</span> m_radius<span class="operator">,</span> m_fontSize);
              update(rectBefore <span class="operator">|</span> rectAfter);
          }
      }
  }

  <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> PathDeformRenderer<span class="operator">::</span>lensDeform(<span class="keyword">const</span> <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> <span class="operator">&amp;</span>source<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> <span class="operator">&amp;</span>offset)
  {
      <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> path;
      path<span class="operator">.</span>addPath(source);

      <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> flip <span class="operator">=</span> m_intensity <span class="operator">/</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">100</span>);

      <span class="keyword">for</span> (<span class="type">int</span> i<span class="operator">=</span><span class="number">0</span>; i<span class="operator">&lt;</span>path<span class="operator">.</span>elementCount(); <span class="operator">+</span><span class="operator">+</span>i) {
          <span class="keyword">const</span> <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span><span class="operator">::</span>Element <span class="operator">&amp;</span>e <span class="operator">=</span> path<span class="operator">.</span>elementAt(i);

          <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> x <span class="operator">=</span> e<span class="operator">.</span>x <span class="operator">+</span> offset<span class="operator">.</span>x();
          <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> y <span class="operator">=</span> e<span class="operator">.</span>y <span class="operator">+</span> offset<span class="operator">.</span>y();

          <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> dx <span class="operator">=</span> x <span class="operator">-</span> m_pos<span class="operator">.</span>x();
          <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> dy <span class="operator">=</span> y <span class="operator">-</span> m_pos<span class="operator">.</span>y();
          <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> len <span class="operator">=</span> m_radius <span class="operator">-</span> <a href="../qtcore/qtmath.html#qSqrt">qSqrt</a>(dx <span class="operator">*</span> dx <span class="operator">+</span> dy <span class="operator">*</span> dy);

          <span class="keyword">if</span> (len <span class="operator">&gt;</span> <span class="number">0</span>) {
              path<span class="operator">.</span>setElementPositionAt(i<span class="operator">,</span>
                                        x <span class="operator">+</span> flip <span class="operator">*</span> dx <span class="operator">*</span> len <span class="operator">/</span> m_radius<span class="operator">,</span>
                                        y <span class="operator">+</span> flip <span class="operator">*</span> dy <span class="operator">*</span> len <span class="operator">/</span> m_radius);
          } <span class="keyword">else</span> {
              path<span class="operator">.</span>setElementPositionAt(i<span class="operator">,</span> x<span class="operator">,</span> y);
          }

      }

      <span class="keyword">return</span> path;
  }

  <span class="type">void</span> PathDeformRenderer<span class="operator">::</span>paint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">*</span>painter)
  {
      <span class="type">int</span> pad_x <span class="operator">=</span> <span class="number">5</span>;
      <span class="type">int</span> pad_y <span class="operator">=</span> <span class="number">5</span>;

      <span class="type">int</span> skip_x <span class="operator">=</span> <a href="../qtcore/qtglobal.html#qRound">qRound</a>(m_pathBounds<span class="operator">.</span>width() <span class="operator">+</span> pad_x <span class="operator">+</span> m_fontSize<span class="operator">/</span><span class="number">2</span>);
      <span class="type">int</span> skip_y <span class="operator">=</span> <a href="../qtcore/qtglobal.html#qRound">qRound</a>(m_pathBounds<span class="operator">.</span>height() <span class="operator">+</span> pad_y);

      painter<span class="operator">-</span><span class="operator">&gt;</span>setPen(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>NoPen);
      painter<span class="operator">-</span><span class="operator">&gt;</span>setBrush(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>black);

      <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> clip(painter<span class="operator">-</span><span class="operator">&gt;</span>clipPath()<span class="operator">.</span>boundingRect());

      <span class="type">int</span> overlap <span class="operator">=</span> pad_x <span class="operator">/</span> <span class="number">2</span>;

      <span class="keyword">for</span> (<span class="type">int</span> start_y<span class="operator">=</span><span class="number">0</span>; start_y <span class="operator">&lt;</span> height(); start_y <span class="operator">+</span><span class="operator">=</span> skip_y) {

          <span class="keyword">if</span> (start_y <span class="operator">&gt;</span> clip<span class="operator">.</span>bottom())
              <span class="keyword">break</span>;

          <span class="type">int</span> start_x <span class="operator">=</span> <span class="operator">-</span>overlap;
          <span class="keyword">for</span> (; start_x <span class="operator">&lt;</span> width(); start_x <span class="operator">+</span><span class="operator">=</span> skip_x) {

              <span class="keyword">if</span> (start_y <span class="operator">+</span> skip_y <span class="operator">&gt;</span><span class="operator">=</span> clip<span class="operator">.</span>top() <span class="operator">&amp;</span><span class="operator">&amp;</span>
                  start_x <span class="operator">+</span> skip_x <span class="operator">&gt;</span><span class="operator">=</span> clip<span class="operator">.</span>left() <span class="operator">&amp;</span><span class="operator">&amp;</span>
                  start_x <span class="operator">&lt;</span><span class="operator">=</span> clip<span class="operator">.</span>right()) {
                  <span class="keyword">for</span> (<span class="type">int</span> i<span class="operator">=</span><span class="number">0</span>; i<span class="operator">&lt;</span>m_paths<span class="operator">.</span>size(); <span class="operator">+</span><span class="operator">+</span>i) {
                      <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> path <span class="operator">=</span> lensDeform(m_paths<span class="operator">[</span>i<span class="operator">]</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(start_x<span class="operator">,</span> start_y));
                      painter<span class="operator">-</span><span class="operator">&gt;</span>drawPath(path);
                  }
              }
          }
          overlap <span class="operator">=</span> skip_x <span class="operator">-</span> (start_x <span class="operator">-</span> width());

      }

      <span class="keyword">if</span> (preferImage()) {
          painter<span class="operator">-</span><span class="operator">&gt;</span>drawImage(m_pos <span class="operator">-</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(m_radius <span class="operator">+</span> LENS_EXTENT<span class="operator">,</span> m_radius <span class="operator">+</span> LENS_EXTENT)<span class="operator">,</span>
                             m_lens_image);
      } <span class="keyword">else</span> {
          painter<span class="operator">-</span><span class="operator">&gt;</span>drawPixmap(m_pos <span class="operator">-</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(m_radius <span class="operator">+</span> LENS_EXTENT<span class="operator">,</span> m_radius <span class="operator">+</span> LENS_EXTENT)<span class="operator">,</span>
                              m_lens_pixmap);
      }
  }

  <span class="type">void</span> PathDeformRenderer<span class="operator">::</span>setRadius(<span class="type">int</span> radius)
  {
      <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> max <span class="operator">=</span> <a href="../qtcore/qtglobal.html#qMax">qMax</a>(m_radius<span class="operator">,</span> (<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>)radius);
      m_radius <span class="operator">=</span> radius;
      generateLensPixmap();
      <span class="keyword">if</span> (<span class="operator">!</span>m_animated <span class="operator">|</span><span class="operator">|</span> m_radius <span class="operator">&lt;</span> max) {
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
          <span class="keyword">if</span> (usesOpenGL()){
              update();
              <span class="keyword">return</span>;
          }
  <span class="preprocessor">#endif</span>
          update(circle_bounds(m_pos<span class="operator">,</span> max<span class="operator">,</span> m_fontSize));
      }
  }

  <span class="type">void</span> PathDeformRenderer<span class="operator">::</span>setIntensity(<span class="type">int</span> intensity)
  {
      m_intensity <span class="operator">=</span> intensity;
      <span class="keyword">if</span> (<span class="operator">!</span>m_animated) {
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
          <span class="keyword">if</span> (usesOpenGL()) {
              update();
              <span class="keyword">return</span>;
          }
  <span class="preprocessor">#endif</span>
          update(circle_bounds(m_pos<span class="operator">,</span> m_radius<span class="operator">,</span> m_fontSize));
      }
  }

</pre>
</div>
<!-- @@@painting/deform/pathdeform.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
